package com.example.myapplication;
/**
 * Created by ASUS on 2016/11/18.
 */
import android.app.Dialog;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

/**
 * @author IdeasAndroid
 *         可展开（收缩）列表示例
 */
public class ListViewad extends BaseExpandableListAdapter {
    Dialog dialog;
    private Context mContext = null;
    private List<Integer> groupList;
    private List<List<Integer>> itemList ;
    public ListViewad(Context context, List<Integer>groupList,List<List<Integer>>itemList) {
        this.mContext = context;
        this.itemList=itemList;
        this.groupList=groupList;
    }

    /**
     * 初始化数据，将相关数据放到List中，方便处理
     */


    public boolean areAllItemsEnabled() {
        return false;
    }

    /*
     * 设置子节点对象，在事件处理时返回的对象，可存放一些数据
     */
    public Object getChild(int groupPosition, int childPosition) {
        return itemList.get(groupPosition).get(childPosition);
    }

    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    /*
     * 字节点视图，这里我们显示一个文本对象
     */
    public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        ViewHolder h = null;
        if (convertView == null) {
            h = new ViewHolder();
            LayoutInflater inflater = LayoutInflater.from(mContext);
            convertView = inflater.inflate(R.layout.item_list5, null);
            convertView.setTag(h);
        } else {
            h = (ViewHolder) convertView.getTag();
        }
        h.l1= (LinearLayout) convertView.findViewById(R.id.l1);
        h.l2= (LinearLayout) convertView.findViewById(R.id.l2);
        h.l3= (LinearLayout) convertView.findViewById(R.id.l3);
        Log.d("date",itemList.get(groupPosition).get(childPosition)+"");
        if(itemList.get(groupPosition).get(childPosition)%3==1){
            h.l1.setVisibility(View.VISIBLE);
            h.l2.setVisibility(View.INVISIBLE);
            h.l3.setVisibility(View.INVISIBLE);
        }else if(itemList.get(groupPosition).get(childPosition)%3==2){
            h.l1.setVisibility(View.VISIBLE);
            h.l2.setVisibility(View.VISIBLE);
            h.l3.setVisibility(View.INVISIBLE);
        }else if(itemList.get(groupPosition).get(childPosition)%3==0){
            h.l1.setVisibility(View.VISIBLE);
            h.l2.setVisibility(View.VISIBLE);
            h.l3.setVisibility(View.VISIBLE);
        }







        h.l1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               // 3*childPosition+1;

                Toast.makeText(mContext,"我是第"+(3*childPosition+1),Toast.LENGTH_SHORT).show();

            }
        });

        h.l2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //
                Toast.makeText(mContext,"我是第"+(3*childPosition+2),Toast.LENGTH_SHORT).show();
            }
        });

        h.l3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 3*childPosition+3;
                Toast.makeText(mContext,"我是第"+(3*childPosition+3),Toast.LENGTH_SHORT).show();
            }
        });










        return convertView;
    }


    /*
     * 返回当前分组的字节点个数
     */
    public int getChildrenCount(int groupPosition) {
        return itemList.get(groupPosition).size();
    }

    /*
     * 返回分组对象，用于一些数据传递，在事件处理时可直接取得和分组相关的数据
     */
    public Object getGroup(int groupPosition) {
        return groupList.get(groupPosition);
    }

    /*
     * 分组的个数
     */
    public int getGroupCount() {
        return groupList.size();
    }

    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    /*
     * 分组视图，这里也是一个文本视图
     */
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            convertView = inflater.inflate(R.layout.name_item, null);
        }
        ImageView iv = (ImageView) convertView.findViewById(R.id.tubiao);
        TextView text = (TextView) convertView.findViewById(R.id.content_001);
        return convertView;
    }

    /*
     * 判断分组是否为空，本示例中数据是固定的，所以不会为空，我们返回false
     * 如果数据来自数据库，网络时，可以把判断逻辑写到这个方法中，如果为空
     * 时返回true
     */
    public boolean isEmpty() {
        return false;
    }

    /*
     * 收缩列表时要处理的东西都放这儿
     */
    public void onGroupCollapsed(int groupPosition) {

    }

    /*
     * 展开列表时要处理的东西都放这儿
     */
    public void onGroupExpanded(int groupPosition) {

    }

    /*
     * Indicates whether the child and group IDs are stable across changes to
     * the underlying data.
     */
    public boolean hasStableIds() {
        return false;
    }

    /*
     * Whether the child at the specified position is selectable.
     */
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }


    class ViewHolder {

        LinearLayout l1;
        LinearLayout l2;
        LinearLayout l3;

    }


}
